#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年5月29日

@author: chenyongbing
'''
import sys,os
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]

class ReadRadata(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        
    def read_rawdata_from_group_zip_file(self,rawpath='',group=None,day=None):
        pass

    def read_employee_rssi_from_rawdata(self,rawpath='',group=None,st=None,et=None,employees=[]):
        datas = []
        if len(employees)==0:
            comp_group  = myRetailDatas.get_comp_group( shop_group=group)
            employees = myZhimindDatas.get_employees( mtype=1,group=comp_group)
        if len(employees)==0:
            return datas
        if len(rawpath)==0 or rawpath=='':
            rawpath = myLocalConfig.rawdata_path
        
        days = myTimeMethod.get_slist_between_st_et(st, et)
        
        for day in days:
            rawfile_tar = rawpath+'/rawdata_group/'+day+'/'+group+'.txt.tar.gz'
            #print rawfile_tar
            if not os.path.exists(rawfile_tar):
                logging.warning( 'rawfile %s not exists.'%rawfile_tar)
                continue
            output = self.openTarFile(rawfile_tar)
            logging.info( "%s,%s"%(rawfile_tar,len(output)))
            for line in output.split('\n'):
                msgLine = line.split('.')
                #print len(msgLine)
                if len(msgLine)!=6 and len(msgLine)!=5:
                    continue
                if len(msgLine)==6:
                    day,dev,dmac,dtime,rssi,rtime = msgLine
                elif len(msgLine)==5:
                    day,dev,dmac,dtime,rssi = msgLine
                if len(dev)>12:continue
                if not re.search('^-[\d]+$',rssi):continue
                if dmac not in employees:continue
                datas.append([day,dev,dmac,rssi])
            logging.info( "found %s"%len(datas))
        return datas
    
    def read_rawdata_from_device_zip_file(self):
        pass
    
    
    def read_rawdata_from_all_zip_file(self):
        pass
if __name__ == '__main__':
    pass